package com.party.core.service.partner.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.partner.MemberPartnerReadDao;
import com.party.core.dao.write.partner.MemberPartnerWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.member.Member;
import com.party.core.model.partner.MemberPartner;
import com.party.core.service.partner.IMemberPartnerService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Description:
 * @Author: yangshoukun
 * @Date: 2018/7/3 14:14
 */
@Service
public class MemberPartnerService implements IMemberPartnerService {

    @Autowired
    private MemberPartnerReadDao memberPartnerReadDao;

    @Autowired
    private MemberPartnerWriteDao memberPartnerWriteDao;

    @Override
    public String insert(MemberPartner memberPartner) {
        BaseModel.preInsert(memberPartner);
        boolean result = memberPartnerWriteDao.insert(memberPartner);
        if (result) {
            return memberPartner.getId();
        }
        return null;
    }

    @Override
    public boolean update(MemberPartner memberPartner) {
        return memberPartnerWriteDao.update(memberPartner);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return memberPartnerWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return memberPartnerWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return memberPartnerWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return memberPartnerWriteDao.batchDelete(ids);
    }

    @Override
    public MemberPartner get(String id) {
        return memberPartnerReadDao.get(id);
    }

    @Override
    public List<MemberPartner> listPage(MemberPartner memberPartner, Page page) {
        return memberPartnerReadDao.listPage(memberPartner, page);
    }

    @Override
    public List<MemberPartner> list(MemberPartner memberPartner) {
        return listPage(memberPartner, null);
    }

    @Override
    public List<MemberPartner> batchList(Set<String> ids, MemberPartner memberPartner, Page page) {
        return null;
    }

    @Override
    public MemberPartner findByMemberId(String memberId) {
        return memberPartnerReadDao.findByMemberId(memberId);
    }
}
